package ua.yandex.lockfree;

import java.math.BigInteger;
import static java.util.Arrays.sort;
import java.util.concurrent.CountDownLatch;

public class Run {

    public static void main(String[] args) throws InterruptedException {
        final SequenceGenerator sequence = new SequenceGenerator();
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        countDownLatch.await();
                        for (int i = 0; i < 10; i++) {
                            System.out.println(
                                    Thread.currentThread().getName()
                                    + ": " + sequence.next());
                            Thread.sleep(10);
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, "Thread " + i).start();
        }
        countDownLatch.countDown();
    }
}
